<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-present http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Released under the MIT License.
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------

namespace app\pay\controller;

use cmf\controller\AdminBaseController;
use think\db\Query;
use think\facade\Db;

class IndexController extends AdminBaseController
{

    /**
     * Notes:统计
     * User:
     * DateTime: 2022-01-17 14:10
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function index()
    {
        $data = [];
        $param = $this->request->param();
        $where = ["delete_time" => 0, "status" => 1];
        //日充值,日提币,日代付,日盈利
        $day_start = strtotime(date("Y-m-d 00:00:00", time()));
        $data['day_recharge'] = Db::name("recharge")->where($where)->whereTime('create_time', 'between', [$day_start, time()])->sum("usdt");
        $data['day_cash'] = Db::name("withdrawal")->where($where)->where(["type" => 6])->whereTime('create_time', 'between', [$day_start, time()])->sum("usdt");
        $data['day_pay'] = Db::name("withdrawal")->where($where)->whereIn('type', [1, 2, 3, 4, 5])->whereTime('create_time', 'between', [$day_start, time()])->sum("usdt");
        $data['day_profit'] = Db::name("withdrawal")->where($where)->whereIn('type', [1, 2, 3, 4, 5])->whereTime('create_time', 'between', [$day_start, time()])->sum("profit_usdt");
        //周充值,周提币,周代付,周盈利
        $monday = mktime(0, 0, 0, date('m'), date('d') - date('N') + 1, date('y'));
        $data['monday_recharge'] = Db::name("recharge")->where($where)->whereTime('create_time', 'between', [$monday, time()])->sum("usdt");
        $data['monday_cash'] = Db::name("withdrawal")->where($where)->where(["type" => 6])->whereTime('create_time', 'between', [$day_start, time()])->sum("usdt");
        $data['monday_pay'] = Db::name("withdrawal")->where($where)->whereIn('type', [1, 2, 3, 4, 5])->whereTime('create_time', 'between', [$monday, time()])->sum("usdt");
        $data['monday_profit'] = Db::name("withdrawal")->where($where)->whereIn('type', [1, 2, 3, 4, 5])->whereTime('create_time', 'between', [$monday, time()])->sum("profit_usdt");
        //月充值,月提币,月代付,月盈利
        $month = mktime(0, 0, 0, date('m'), 1, date('Y'));
        $data['month_recharge'] = Db::name("recharge")->where($where)->whereTime('create_time', 'between', [$month, time()])->sum("usdt");
        $data['month_cash'] = Db::name("withdrawal")->where($where)->where(["type" => 6])->whereTime('create_time', 'between', [$day_start, time()])->sum("usdt");
        $data['month_pay'] = Db::name("withdrawal")->where($where)->whereIn('type', [1, 2, 3, 4, 5])->whereTime('create_time', 'between', [$month, time()])->sum("usdt");
        $data['month_profit'] = Db::name("withdrawal")->where($where)->whereIn('type', [1, 2, 3, 4, 5])->whereTime('create_time', 'between', [$month, time()])->sum("profit_usdt");
        //时间筛选 充值,提币,代付,盈利,用户数,充值订单,提币订单,代付订单
        if (isset($param['start_time']) && !empty($param['start_time'])) {
            $start = strtotime($param['start_time']);
        } else {
            $start = $day_start;
        }
        if (isset($param['end_time']) && !empty($param['end_time'])) {
            $end = strtotime($param['end_time']);
        } else {
            $end = time();
        }
        $data['recharge'] = Db::name("recharge")->where($where)->whereTime('create_time', 'between', [$start, $end])->sum("usdt");
        $data['cash'] = Db::name("withdrawal")->where($where)->where(["type" => 6])->whereTime('create_time', 'between', [$day_start, time()])->sum("usdt");
        $data['pay'] = Db::name("withdrawal")->where($where)->whereIn('type', [1, 2, 3, 4, 5])->whereTime('create_time', 'between', [$start, $end])->sum("usdt");
        $data['profit'] = Db::name("withdrawal")->where($where)->whereIn('type', [1, 2, 3, 4, 5])->whereTime('create_time', 'between', [$start, $end])->sum("profit_usdt");
        $this->assign('data', $data);
        $this->assign('start_time', isset($param['start_time']) ? $param['start_time'] : '');
        $this->assign('end_time', isset($param['end_time']) ? $param['end_time'] : '');
        return $this->fetch();
    }


}
